import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/enums/index.dart';
import 'package:geomancy/mock/study_data.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/tools/utils.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/common_text.dart';
import 'package:geomancy/widgets/common_title.dart';
import 'package:geomancy/widgets/direction_grid/index.dart';
import 'package:geomancy/widgets/star_grid/index.dart';
import 'package:go_router/go_router.dart';

class StudyResultPage extends StatefulWidget {
  final CompassSource source;
  final double direction;///罗盘角度
  final String birthday;
  const StudyResultPage({super.key, required this.source, required this.direction, required this.birthday});

  @override
  State<StudyResultPage> createState() => _StudyResultPageState();
}

class _StudyResultPageState extends State<StudyResultPage> {
  late String themeTxt;
  late String station;
  List<int> indexList = [];
  late int zodiacIndex;

  @override
  void initState() {
    super.initState();
    themeTxt = widget.source == CompassSource.roomStudy ? '房间' : '工位';
    station = Utils.getCompassStation(widget.direction);
    indexList = StudyData.gridData[station]['zaiIndexList'];
    final index = Utils.getZodiacIndex(widget.birthday);
    final zodiac = Utils.getZodiacPinYinBybIndex(index);
    zodiacIndex = StudyData.gridZodiacData[zodiac];
  }


  backHandle() {
    context.go('/');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonHeader.appBar(context: context),
      backgroundColor: ColorStyle.pageDefaultColor,
      body: ListView(
        physics: const ClampingScrollPhysics(),
        padding: EdgeInsets.fromLTRB(Constant.PAGEPADDING.w, 20.w, Constant.PAGEPADDING.w, Constant.PAGEPADDING.w),
        children: [
          CommonTitleWidget(txt: '$themeTxt文昌位'),
          Container(
            height: 160.w,
            margin: EdgeInsets.symmetric(vertical: 20.w),
            padding: EdgeInsets.symmetric(horizontal: 40.w),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: CommonText(txt: '所测$themeTxt文昌位方位如下，详情请点击文昌位查看。', height: 1.5),
          ),
          ///宅文昌位九宫格
          DirectionGridWidget(
            activeList: indexList,
            isOpacity: widget.source == CompassSource.stationStudy,
            source: widget.source,
            direction: widget.direction,
          ),
          Container(
            margin: EdgeInsets.only(bottom: 80.w, top: 40.w),
            padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 40.w),
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: const CommonText(height: 1.5, txt: '古语有云“身在文昌位，考得状元郎”。屋宅文昌位及文昌星飞临入宅的方位。文昌位要保持明亮、干净整洁，忌横梁压顶和无依靠。激发文昌位可以让学业达到事半功倍的效果。'),
          ),
          const CommonTitleWidget(txt: '本命文昌位'),
          Container(
            margin: EdgeInsets.symmetric(vertical: 20.w),
            padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 40.w),
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: const CommonText(height: 1.5, txt: '本命文昌位依据个人命理信息得出，是一个人一生永不改变的方位。'),
          ),
          ///本命文昌位九宫格
          Container(
            margin: EdgeInsets.only(bottom: 80.w),
            child: DirectionGridWidget(
              activeList: [zodiacIndex],
              source: widget.source,
              isSelf: true,
            ),
          ),
          CommonTitleWidget(txt: '${Utils.getCurrentYear()}年九宫飞星文昌位'),
          Container(
            margin: EdgeInsets.only(top: 20.w, bottom: 40.w),
            child: const StarGridWidget(activeList: [5]),
          ),
          ///模拟虚线
          Row(
            children: List.filled(66, const SizedBox()).map((e) => Container(
              width: 10.w,
              height: 1.w,
              decoration: const BoxDecoration(
                gradient: LinearGradient(
                  colors: [Colors.black, Colors.transparent],
                  stops: [0.5, 1.0],
                  tileMode: TileMode.repeated, // 重复模式，形成虚线效果
                ),
              ),
            )).toList(),
          ),
          Container(
            margin: EdgeInsets.only(top: 40.w),
            padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 40.w),
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: const Column(
              children: [
                CommonText(height: 1.5, txt: '以上三种文昌位分别为：工位文昌位、本命文昌位、流年文昌位。对于专属工位，上述三种文昌位的能量排名为：工位文昌位＞流年文昌位＞本命文昌位。'),
                CommonText(height: 1.5, txt: '● 以上三种文昌位若能占其中之一便可得数年文运，若三种文昌位方位有两两重合甚至三种方位全部重合，便更是事半功倍“文到功成”。')
              ],
            ),
          ),
        ],
      ),
    );
  }
}
